﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace GameTank
{
    public class ModelDTO
    {
        string filePath = "";
       
        public string FilePath
        {
            get { return filePath; }
            set { filePath = value; }
        }

        
        int nFrame = 1;

        public int NFrame
        {
            get { return nFrame; }
            set { nFrame = value; }
        }

        int nDirection = 1;

        public int NDirection
        {
            get { return nDirection; }
            set { nDirection = value; }
        }

        public XElement ToXml()
        {
            XElement element = new XElement("ModelDTO");
            element.SetAttributeValue("filePath", this.FilePath);
            element.SetAttributeValue("nFrame", this.nFrame);
            element.SetAttributeValue("nDirection", this.nDirection);
            return element;
        }

        public static ModelDTO Parse(XElement modelElement)
        {
            ModelDTO temp = new ModelDTO();
            temp.FilePath = modelElement.Attribute("filePath").Value;
            temp.nFrame = int.Parse(modelElement.Attribute("nFrame").Value);
            temp.nDirection = int.Parse(modelElement.Attribute("nDirection").Value);
            return temp;
        }

        public void SaveToFile(String fileName)
        {
            XDocument doc = new XDocument();
            doc.Add(ToXml());
            doc.Save(fileName);
        }
    }
}
